﻿using FineAdmin.IService;
using FineAdmin.Model;
using FineAdmin.Web.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FineAdmin.Web.Areas.Shop.Controllers
{
    public class MaterialSetController : BaseController
    {
        // GET: Shop/MaterialSet
        public IMaterialService MaterialService { get; set; }
        public override ActionResult Index(int? id)
        {
            base.Index(id);
            return View();
        }

        [HttpGet]
        public JsonResult List(MaterialModel model, PageInfo pageInfo)
        {
            pageInfo.field = "Id";
            pageInfo.order = "asc";
            var result = MaterialService.GetListByFilter(model, pageInfo);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult RefreshData(int id = -1) {

            var result = MaterialService.RefreshData(id) > 0 ? SuccessTip("成功") : ErrorTip("失败");
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        public ActionResult Edit(int id)
        {

            var model = MaterialService.GetById(id);
            return View(model);
        }
        [HttpPost]
        public ActionResult Edit(MaterialModel model)
        {
            model.UpdateTime = DateTime.Now;
            model.UpdateUserId = Operator.UserId;
            var result = MaterialService.UpdateById(model) ? SuccessTip("修改成功") : ErrorTip("修改失败");
            return Json(result);
        }
    }
}